package com.stylefeng.guns.modular.registration.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.Registration;
import com.stylefeng.guns.modular.registration.service.IRegistrationService;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.security.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 报名信息控制器
 *
 * @author fengshuonan
 * @Date 2018-08-08 00:00:44
 */
@Controller
@RequestMapping("/registration")
public class RegistrationController extends BaseController {

    private String PREFIX = "/registration/registration/";

    @Autowired
    private IRegistrationService registrationService;

    /**
     * 跳转到报名信息首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "registration.html";
    }

    /**
     * 跳转到添加报名信息
     */
    @RequestMapping("/registration_add")
    public String registrationAdd() {
        return PREFIX + "registration_add.html";
    }

    /**
     * 跳转到修改报名信息
     */
    @RequestMapping("/registration_update/{registrationId}")
    public String registrationUpdate(@PathVariable Integer registrationId, Model model) {
        Registration registration = registrationService.selectById(registrationId);
        model.addAttribute("item",registration);
        LogObjectHolder.me().set(registration);
        return PREFIX + "registration_edit.html";
    }

    /**
     * 获取报名信息列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return registrationService.selectList(null);
    }

    /**
     * 新增报名信息
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Registration registration) {
        registrationService.insert(registration);
        return SUCCESS_TIP;
    }

    /**
     * 删除报名信息
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer registrationId) {
        registrationService.deleteById(registrationId);
        return SUCCESS_TIP;
    }

    /**
     * 修改报名信息
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Registration registration) {
        registrationService.updateById(registration);
        return SUCCESS_TIP;
    }

    /**
     * 报名信息详情
     */
    @RequestMapping(value = "/detail/{registrationId}")
    @ResponseBody
    public Object detail(@PathVariable("registrationId") Integer registrationId) {
        return registrationService.selectById(registrationId);
    }
}
